package com.mh.controller;

import com.mh.common.ResponseResult;
import com.mh.entity.LoginBody;
import com.mh.entity.SysUser;
import com.mh.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

@RestController
public class LoginController {

    @Autowired
    private LoginService loginService;

    @CrossOrigin(origins = "http://localhost:8080")
    //用于启用跨域资源共享(CORS),允许指定的来源(Origin)访问当前服务的资源
    //用于在控制器或方法上启用 CORS 支持,适用于局部配置
    @PostMapping("/user/login2")
    public ResponseResult login2(@RequestBody SysUser user) {
        return loginService.login(user);
    }

    @GetMapping("/user/logout")
    public ResponseResult logout() {
        return loginService.logout();
    }

    @PostMapping("/user/login")
    public ResponseResult login(@RequestBody LoginBody loginBody) {

        return loginService.captchaLogin(loginBody);
    }
}
